/***************************************************************************//**
 * @file GUI/ComboAircraftTypes.cpp
 * @author  Marek M. Cel <marekcel@mscsim.org>
 *
 * @section LICENSE
 *
 * Copyright (C) 2014 Marek M. Cel
 *
 * This file is part of MScSim. You can redistribute and modify it under
 * the terms of GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.
 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Further information about the GNU General Public License can also be found
 * on the world wide web at http://www.gnu.org.
 ******************************************************************************/
#ifndef COMBO_AIRCRAFT_TYPES_CPP
#define COMBO_AIRCRAFT_TYPES_CPP
#endif

////////////////////////////////////////////////////////////////////////////////

#include <GUI/ComboAircraftTypes.h>

////////////////////////////////////////////////////////////////////////////////

ComboAircraftTypes::ComboAircraftTypes( QWidget *parent ) :
    QComboBox( parent )
{
}

////////////////////////////////////////////////////////////////////////////////

ComboAircraftTypes::~ComboAircraftTypes() {}

////////////////////////////////////////////////////////////////////////////////

bool ComboAircraftTypes::read( QIODevice *device )
{
    if ( !m_domDocument.setContent(device, true) )
    {
        return false;
    }

    QDomElement root = m_domDocument.documentElement();

    if ( root.tagName() != "aircraft_types" )
    {
        return false;
    }

    QDomElement child = root.firstChildElement( "aircraft_type" );

    while ( !child.isNull() )
    {
        parseAircraftTyleElement( child );
        child = child.nextSiblingElement( "aircraft_type" );
    }

    return true;
}

////////////////////////////////////////////////////////////////////////////////

void ComboAircraftTypes::parseAircraftTyleElement( const QDomElement &element )
{
    QString aircraftName = element.firstChildElement( "name" ).text();

    addItem( aircraftName );
}
